/**
 * Controls.m by Giraldo Rosales.
 * Visit www.liquidgear.net for documentation and updates.
 *
 * Copyright (c) 2009 Nitrogen Design, Inc. All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 **/

#import "Controls.h"
#import "Video.h"

@implementation Controls

// MPMoviePlayerController will play movies full-screen in 
// landscape mode, so we must rotate MyOverlayView 90 degrees and 
// translate it to the center of the screen so when it draws
// on top of the playing movie it will display in landscape 
// mode to match the movie player orientation.
- (void)awakeFromNib {
	CGAffineTransform transform = self.transform;
	
	// Rotate the view 90 degrees. 
	transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
	
	UIScreen *screen = [UIScreen mainScreen];
	
	// Translate the view to the center of the screen
	transform = CGAffineTransformTranslate(transform, ((screen.bounds.size.height) - (self.bounds.size.height))/2, 0);
	self.transform = transform;
}

- (void)dealloc {
	[super dealloc];
}

// Handle any touches to the overlay view
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch* touch = [touches anyObject];
	if (touch.phase == UITouchPhaseBegan) {
		// IMPORTANT:
		// Touches to the overlay view are being handled using
		// two different techniques as described here:
		//
		// 1. Touches to the overlay view (not in the button)
		//
		// On touches to the view we will post a notification
		// "overlayViewTouch". MyViewController is registered 
		// as an observer for this notification, and the 
		// overlayViewTouches: method in MyViewController
		// will be called. 
		//
		// 2. Touches to the button 
		//
		// Touches to the button in this same view will 
		// trigger the MyViewController overlayViewButtonPress:
		// action method instead.
		
		NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
		[nc postNotificationName:OverlayViewTouchNotification object:nil];
	}    
}

@end
